package com.sunwayhorizo.health.hl7.persistent;

import com.sunwayhorizo.health.hl7.datatypes.common.CSImpl;
import com.sunwayhorizo.health.hl7.persistent.pk.RimCoreEntyTelAddrsPK;

import java.io.Serializable;

import java.sql.Timestamp;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;


@Entity
@TableGenerator(name="EntityTelAddrs_IdGenerator", table="RIM_Id_Generator", pkColumnName = "pkColumn", valueColumnName = "valueColumn",pkColumnValue="Enty_TelAddrs")
@NamedQuery(name = "RimCoreEntyTelAddrs.findAll", query = "select o from RimCoreEntyTelAddrs o")
@Table(name = "RIM_CORE_ENTY_TEL_ADDRS")
@IdClass(RimCoreEntyTelAddrsPK.class)
public class RimCoreEntyTelAddrs implements Serializable {
    @Id
    @Column(name="ENTITY_ID", nullable = false, insertable = false,  updatable = false)    private Long entityId;
    @Id
    @Column(name="ENTITY_VERSION_NUM", nullable = false, insertable = false,  updatable = false)    private Long entityVersionNum;
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE,generator = "EntityTelAddrs_IdGenerator" )
    @Column(name="TEL_ADDRESS_ID", nullable = false)    private Long telAddressId;
    
    @Column(name="ADDRESS_TXT")    private String address;
    @Column(name="CONTACT_POINT_ID")    private Long contactPointId;
    @Column(name="EFFECTIVE_END_DATE_TS")    private Timestamp effectiveEndDateTs;
    @Column(name="EFFECTIVE_GTS_TXT")    private String effectiveGtsTxt;
    @Column(name="EFFECTIVE_START_DATE_TS")    private Timestamp effectiveStartDateTs;
    
    @Column(name="URL_SCHEME_CODE", nullable = false)    private String scheme;
    
    @OneToMany(mappedBy = "rimCoreEntyTelAddrs",cascade = CascadeType.ALL, fetch = FetchType.LAZY)    
    private List<RimCoreEntyTelUses> entyTelUsesList = new ArrayList();
    
    @ManyToOne
    @JoinColumns({
    @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID"),
    @JoinColumn(name = "ENTITY_VERSION_NUM", referencedColumnName = "ENTITY_VERSION_NUM")
    })
    private RimCoreEntities rimCoreEntities;

    public RimCoreEntyTelAddrs() {
    }

    public Long getContactPointId() {
        return contactPointId;
    }

    public void setContactPointId(Long contactPointId) {
        this.contactPointId = contactPointId;
    }

    public Timestamp getEffectiveEndDateTs() {
        return effectiveEndDateTs;
    }

    public void setEffectiveEndDateTs(Timestamp effectiveEndDateTs) {
        this.effectiveEndDateTs = effectiveEndDateTs;
    }

    public String getEffectiveGtsTxt() {
        return effectiveGtsTxt;
    }

    public void setEffectiveGtsTxt(String effectiveGtsTxt) {
        this.effectiveGtsTxt = effectiveGtsTxt;
    }

    public Timestamp getEffectiveStartDateTs() {
        return effectiveStartDateTs;
    }

    public void setEffectiveStartDateTs(Timestamp effectiveStartDateTs) {
        this.effectiveStartDateTs = effectiveStartDateTs;
    }

    public Long getEntityId() {
        return entityId;
    }

    public void setEntityId(Long entityId) {
        this.entityId = entityId;
    }

    public Long getEntityVersionNum() {
        return entityVersionNum;
    }

    public void setEntityVersionNum(Long entityVersionNum) {
        this.entityVersionNum = entityVersionNum;
    }

    public Long getTelAddressId() {
        return telAddressId;
    }

    public void setTelAddressId(Long telAddressId) {
        this.telAddressId = telAddressId;
    }


    private RimCoreEntyTelUses addRimCoreEntyTelUses(RimCoreEntyTelUses rimCoreEntyTelUses) {
        getEntyTelUsesList().add(rimCoreEntyTelUses);
        rimCoreEntyTelUses.setRimCoreEntyTelAddrs(this);
        return rimCoreEntyTelUses;
    }

    private RimCoreEntyTelUses removeRimCoreEntyTelUses(RimCoreEntyTelUses rimCoreEntyTelUses) {
        getEntyTelUsesList().remove(rimCoreEntyTelUses);
        rimCoreEntyTelUses.setRimCoreEntyTelAddrs(null);
        return rimCoreEntyTelUses;
    }
    public void setEntyTelAddrUses(Set mSet){
        CSImpl use = (CSImpl)mSet.iterator().next();
        RimCoreEntyTelUses entyAddrTelUses = new RimCoreEntyTelUses();
        entyAddrTelUses.setUse(use.code().toString());
        this.addRimCoreEntyTelUses(entyAddrTelUses);            
    }

    public void setRimCoreEntities(RimCoreEntities rimCoreEntities) {
        this.rimCoreEntities = rimCoreEntities;
    }

    public RimCoreEntities getRimCoreEntities() {
        return rimCoreEntities;
    }

    public void setEntyTelUsesList(List<RimCoreEntyTelUses> entyTelUsesList) {
        this.entyTelUsesList = entyTelUsesList;
    }

    public List<RimCoreEntyTelUses> getEntyTelUsesList() {
        return entyTelUsesList;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAddress() {
        return address;
    }

    public void setScheme(String scheme) {
        this.scheme = scheme;
    }

    public String getScheme() {
        return scheme;
    }
}
